/*
 * KKTouch.h
 *
 *  Created on: 2013-9-15
 *      Author: wanghua
 */

#ifndef KKTOUCH_H_
#define KKTOUCH_H_

#include "kaka_common.h"
#include <iostream>

using namespace std;

USING_NS_CC;

class KKTouch: public cocos2d::CCObject {
private:
	;CC_SYNTHESIZE(bool,m_bubbled,Bubbled)
	;CC_SYNTHESIZE(bool,m_handled,Handled)
	;CC_SYNTHESIZE(bool,m_moved,IsMoved)
	;CC_SYNTHESIZE(int,m_viewId,ViewId)
	;CC_SYNTHESIZE(CCPoint,m_point,Point)
	;CC_SYNTHESIZE(CCPoint,m_prevPoint,PrevPoint)
	;CC_SYNTHESIZE(CCPoint,m_firstPoint,FirstPoint)
	;CC_SYNTHESIZE(CCPoint,m_rawPoint,RawPoint)
	;CC_SYNTHESIZE(CCPoint,m_prevRawPoint,PrevRawPoint)
	;CC_SYNTHESIZE(CCPoint,m_firstRawPoint,FirstRawPoint)
public:

	KKTouch(const KKTouch& touch);

	KKTouch(const KKTouch& touch, const CCPoint& point);

	KKTouch(CCTouch* ccTouch);

	KKTouch();

	virtual ~KKTouch();

	CCPoint getFling();

	void copy(const KKTouch& touch);
};

typedef KKDictionary<int, KKTouch*> KKTouchDictionary;

class KKTouchHolder: public CCObject {

private:
	;CC_SYNTHESIZE(KKTouchDictionary*,m_touches,Touches)
	;

public:

	KKTouchHolder() {
		m_touches = new KKTouchDictionary();
	}

	virtual ~KKTouchHolder() {
		CC_SAFE_DELETE(m_touches);
	}

	KKTouch* getTouch(const int viewId) {
		return m_touches->objectForKey(viewId);
	}

	KKTouch* getTouch() {
		if (m_touches->begin()) {
			return m_touches->next();
		}

		return NULL;
	}

	KKTouch* updateTouch(const KKTouch& newTouch) {

		KKTouch* touch = m_touches->objectForKey(newTouch.getViewId());

		if (!touch) {
			touch = new KKTouch(newTouch);
			m_touches->setObject(touch, touch->getViewId());
		} else {
			touch->setPrevPoint(touch->getPoint());
			touch->setPrevRawPoint(touch->getRawPoint());
			touch->setPoint(newTouch.getPoint());
			touch->setRawPoint(newTouch.getRawPoint());
		}

		return touch;
	}

	void removeTouch(const KKTouch& newTouch) {
		m_touches->removeObjectForKey(newTouch.getViewId());
	}

};
#endif /* KKTOUCH_H_ */
